<?php

// [ PC ]

namespace app\index\controller;
use think\Controller;
use think\Session;
use app\wechat\lib\ScanOauth;

class Index extends Controller
{
    // 首页
    // http://jzl.51dojob.com
    // http://jzl.io
    public function index()
    {
		return $this->fetch();
    }

    // 登录
    // http://jzl.51dojob.com/login
    public function login()
    {
        return $this->fetch();
    }

    // 微信扫码授权回调
    // http://jzl.51dojob.com/wx_scan_oauth_callback
    public function wx_scan_oauth_callback()
    {
        $state  = $this->request->get('state/s','','trim');
        $code   = $this->request->get('code/s',null,'trim');
        $result = ScanOauth::callback($state,$code);
        switch ($result) {
            case 'success':          // 登录成功,跳转会员中心
                $this->redirect('@member');
                break;
            case 'csrf':             // 跨站请求伪造攻击,跳转对应提示页面
                return '跨站请求伪造攻击';
                break;
            case 'user_not_allow':   // 用户禁止授权,跳转对应提示页面
                return '用户禁止授权';
                break;
            case 'bind':             // 帐号不存在,绑定用户,跳转绑定手机号页面
                $this->redirect('@member/bind');
                break;
            default:
                return 'Wechat Authorization Failure.';
                break;
        }
    }

    // 找回密码
    // http://jzl.51dojob.com/forgot
    public function forgot()
    {
        return $this->fetch();
    }

    // 注册
    // http://jzl.51dojob.com/register
    public function register()
    {
        return $this->fetch();
    }

    // 微信扫码登录,绑定手机|选择角色,设置密码
    // http://jzl.51dojob.com/bind
    public function bind()
    {
        Session::has('wechat') || $this->redirect('/');
        return $this->fetch();
    }

    // 关于价值链
    // http://jzl.51dojob.com/about
    public function about()
    {
        return $this->fetch();
    }

    // pdf预览
    // http://jzl.51dojob.com/pdf/
    public function pdf()
    {
        //$uri = $this->request->post('uri/s','','trim');

        // ...
        
        return $this->fetch();
    }

    # [ 项目 ]

    // 项目汇选
    // http://jzl.51dojob.com/projects
    public function project_list()
    {
        return $this->fetch();
    }

    // 项目详情
    // http://jzl.51dojob.com/project/ID
    public function project_read($id = 0)
    {
        $this->assign('id',$id);
        return $this->fetch();
    }
}
